package com.loooooo.pm2024.data;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.util.HashMap;


public class Result extends HashMap<String, Object> implements Serializable {
    @JsonProperty("error_code")
    private int errorCode;
    private String message;
    private Object data;
    private Object extData;
    private long now = System.currentTimeMillis();

    public Result() {
        setErrorCode(0);
        setMessage(null);
        setData(null);
    }

    public Result(int errorCode, String message, Object data) {
        setErrorCode(errorCode);
        setMessage(message);
        setData(data);
    }


    public int getErrorCode() {
        return errorCode;
    }

    public Result setErrorCode(int errorCode) {
        this.errorCode = errorCode;
        this.put("error_code", errorCode);
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Result setMessage(String message) {
        this.message = message;
        this.put("message", message);
        return this;
    }

    public Object getData() {
        return data;
    }

    public Result setData(Object data) {
        this.data = data;
        this.put("data", data);
        return this;
    }

    public static Result success() {
        return new Result(0, "Success", null);
    }

    public static Result success(Object data) {
        return new Result(0, "Success", data);
    }

    public static Result success(String message, Object data) {
        return new Result(0, message, data);
    }

    public static Result error(int errorCode, String message, Object data) {
        return new Result(errorCode, message, data);
    }

    public static Result error(int errorCode, String message) {
        return new Result(errorCode, message, null);
    }

    public Object getExtData() {
        return extData;
    }

    public Result setExtData(Object extData) {
        this.extData = extData;
        this.put("extData", extData);
        return this;
    }

    public Result set(String key, Object val) {
        put(key, val);
        return this;
    }

    public long getNow() {
        return now;
    }

    public void setNow(long now) {
        this.now = now;
    }
}
